/**
 * Appliance.java
 * 
 * Stores information about a single Appliance including the probability that it is turned on 
 * in any given hour.
 * 
 */

package com.swin.energy;

import java.util.ArrayList;
import java.util.List;

import com.swin.energy.DataGenerator.SEASON;

public class Appliance {

	private String name;
	private Double rate;
	private List<Double> baseProbablity;

	// TODO: Need to add the factors that influence the value to the end of
	// values and store them in this class
	public Appliance(String... values) {
		baseProbablity = new ArrayList<Double>();
		this.name = values[0];
		this.rate = Double.parseDouble(values[1]);
		for (int i = 2; i < values.length; i++)
			this.baseProbablity.add(Double.parseDouble(values[i]));
	}

	public String getName() {
		return this.name;
	}

	public Double getRate() {
		return rate;
	}

	public Double getBaseProbablitlity(int hour) {
		return baseProbablity.get(hour);
	}

	private double maxProbOne(double prob) {
		return prob > 1 ? 1 : prob;
	}
	
	private double minProbZero(double prob) {
		return prob < 0 ? 0 : prob;
	}

	// TODO: Probably should be in ApplianceSetup
	public double getProbability(SEASON season, int hour) {
		// Seasonal influences
		// Base probablitlities based on spring/autumn
		double prob = baseProbablity.get(hour);
		if (season.equals(SEASON.SUMMER)) {
			switch (this.name) {
			case "pc":
				prob = minProbZero(prob - 0.03);
				break;
			case "dryer":
				prob = minProbZero(prob - 0.1);
				break;
			case "heater":
				prob = minProbZero(prob - 0.17);
				break;
			case "tv":
				prob = minProbZero(prob - 0.1);
				break;
			}
		} else if (season.equals(SEASON.WINTER)) {
			switch (this.name) {
			case "pc":
				prob = maxProbOne(prob + 0.1);
				break;
			case "dryer":
				prob = maxProbOne(prob + 0.2);
				break;
			case "heater":
				prob = maxProbOne(prob + 0.19);
				break;
			case "tv":
				prob = maxProbOne(prob + 0.13);
				break;
			}
		}
		return prob;
	}
}
